using System;
using System.Collections.Generic;
using System.Text;
using DTO;
using DAO;
using System.Data;

namespace BUS
{
    /// <summary> 
    ///Author: nnamthach@gmail.com 
    /// <summary>
    public class MaterialDetailControl
    {
        #region Local Variable
        private MaterialDetailDataAccess _objDAO;
        #endregion Local Variable

        #region Method
        public MaterialDetailControl()
        {
            _objDAO = new MaterialDetailDataAccess();
        }

        public MaterialDetailInfo Get(
        String DTB,
        String RequestNo,
        Int32 DetailNo,
        ref string sErr)
        {
            return _objDAO.Get(
            DTB,
            RequestNo,
            DetailNo,
            ref sErr);
        }

        public DataTable GetAll(
        String DTB, string reqNo,
        ref string sErr)
        {
            return _objDAO.GetAll(
            DTB, reqNo,
            ref sErr);
        }
        public DataTable GetByPos(
        String DTB,
        int pos, ref string sErr)
        {
            return _objDAO.GetByPos(
            DTB,
            pos, ref sErr);
        }
        public int GetCountRecord(
        String DTB,
        ref string sErr)
        {
            return _objDAO.GetCountRecord(
            DTB,
            ref sErr);
        }

        public Int32 Add(MaterialDetailInfo obj, ref string sErr)
        {
            return _objDAO.Add(obj, ref sErr);
        }

        public string Update(MaterialDetailInfo obj)
        {
            return _objDAO.Update(obj);
        }

        public string Delete(
        String DTB,
        String RequestNo,
        Int32 DetailNo = -1
        )
        {
            return _objDAO.Delete(
            DTB,
            RequestNo,
            DetailNo
            );
        }
        public Boolean IsExist(
        String DTB,
        String RequestNo,
        Int32 DetailNo
        )
        {
            return _objDAO.IsExist(
            DTB,
            RequestNo,
            DetailNo
            );
        }

        public DataTable Search(String columnName, String columnValue, String condition, String tableName, ref String sErr)
        {
            return _objDAO.Search(columnName, columnValue, condition, tableName, ref  sErr);
        }
        public string InsertUpdate(MaterialDetailInfo obj)
        {
            string sErr = "";
            if (IsExist(
            obj.DTB,
            obj.RequestNo,
            obj.DetailNo
            ))
            {
                sErr = Update(obj);
            }
            else
                Add(obj, ref sErr);
            return sErr;
        }

        public DataTable GetTransferOut(string dtb, object from, object to, ref string sErr)
        {
            return _objDAO.GetTransferOut(dtb, from, to, ref sErr);
        }

        public DataTable ToTransferInStruct()
        {
            return MaterialDetailInfo.ToDataTable();
        }

        public string TransferIn(DataRow row)
        {
            MaterialDetailInfo inf = new MaterialDetailInfo(row);
            return InsertUpdate(inf);
        }
        #endregion Method
        public object BeginTransaction(ref string sErr)
        {
            return _objDAO.BeginTransaction(ref sErr);
        }
        public object SetTransaction(object trans)
        {
            return _objDAO.SetTransaction(trans);
        }
        public bool CommitTransaction(ref string sErr)
        {
            return _objDAO.CommitTransaction(ref sErr);
        }

        public bool RollbackTransaction(ref string sErr)
        {
            return _objDAO.RollbackTransaction(ref sErr);
        }
    }
}
